# -*- coding:utf-8 -*-
# !/usr/bin/env
import threading
from time import sleep
from scrapy_web_py3 import lagouSpider
from sports_spiders.service import JingCaiService
from sports_spiders.config.offline import trade500_constants as trade, jingcai_constants as jcconstants
from sports_spiders.cron import ScrapyRunSpider as scrapy
class Num:
    def __init__(self):
        self.num = 0
        self.sem = threading.Semaphore(value = 3)  # 允许最多三个线程同时访问资源

    def add(self):
        self.sem.acquire()  # 内部计数器减1
        self.num += 1
        num = self.num
        self.sem.release()  # 内部计数器加1
        return num
n = Num()
class MyThread(threading.Thread):
    def __init__(self,func, args, type=0, args2=0):
        threading.Thread.__init__(self)
        self.func = func
        self.args = args
        self.type = type
        self.args2 = args2
        self.sem = threading.Semaphore(value = 30)
        self.thread_lock = threading.Lock()

    def run(self):
        print("多线程开始了")
        if self.type == 1:
            self.thread_lock.acquire()
            lagouSpider.LagouSpider().save_company_url(self.args, self.args2)
            self.thread_lock.release()

        threading_num = threading.activeCount()
        print(threading_num)

# if __name__ == "__main__":
#     import time
#     start = time.time()
#     WHILE_TEAM_OPEN = False
    # if WHILE_TEAM_OPEN is True:
    #     have_match_date = [0, 10000, 10001,20000, 20001,30000, 30001,40000,40001,50000 ]
    #     thing1 = MyThread(func = all_team_downloader, args = 0, args2 = 10000, type = 5)
    #     thing2 = MyThread(func = all_team_downloader, args = 10000, args2 = 20000, type = 5)
    #     thing3 = MyThread(func = all_team_downloader, args = 20000, args2 = 30000, type = 5)
    #     thing4 = MyThread(func = all_team_downloader, args = 30000, args2 = 40000, type = 5)
    #     thing5 = MyThread(func = all_team_downloader, args = 40001, args2 = 50000, type = 5)
    #     thing6 = MyThread(func = all_team_downloader, args = 50000, args2 = 60000, type = 5)
    #     thing1.start()
    #     thing2.start()
    #     thing3.start()
    #     thing4.start()
    #     thing5.start()
    #     thing6.start()
    #     thing1.join()
    #     thing2.join()
    #     thing3.join()
    #     thing4.join()
    #     thing5.join()
    #     thing6.join()

